﻿using System;
using VideoStore.Domain.DAL;
using VideoStore.Domain.Entities;

namespace VideoStore.Business
{
    public class CustomerBusinessObject
    {
        #region Fields

        private readonly ICustomerDataAccess customerDao;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="CustomerBusinessObject"/> class.
        /// </summary>
        public CustomerBusinessObject()
        {
            customerDao = new CustomerDataAccess();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CustomerBusinessObject"/> class.
        /// </summary>
        /// <param name="dao">The DAO.</param>
        public CustomerBusinessObject(ICustomerDataAccess dao)
        {
            // This constructor enables easy TDD as it takes in whatever ICustomerDataAccess implementation.
            customerDao = dao;
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Gets the customer by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Customer GetCustomerById(int id)
        {
            Customer customer;
            try
            {
                customer = customerDao.GetCustomerById(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return customer;
        }

        /// <summary>
        /// Creates the customer.
        /// </summary>
        /// <param name="newCustomer">The new customer.</param>
        /// <returns></returns>
        public Customer CreateCustomer(Customer newCustomer)
        {
            Customer customer;
            try
            {
                customer = customerDao.CreateCustomer(newCustomer);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return customer;
        }

        #endregion
    }
}
